// enum EditOp { Insert, Delete, Replace }  // 删除这一行

fn edit_distance(a: &str, b: &str) -> usize {  
    let mut dp = vec![vec![0; b.len()+1]; a.len()+1];  
    for i in 0..=a.len() {  
        for j in 0..=b.len() {  
            // TODO: 使用 match 处理不同操作  
            dp[i][j] = match (i, j) {
                (0, 0) => 0,
                (0, _) => j,       // 插入j次
                (_, 0) => i,       // 删除i次
                _ => {
                    let insert = dp[i][j-1] + 1;
                    let delete = dp[i-1][j] + 1;
                    //let replace = dp[i-1][j-1] + if a[i-1] == b[j-1] { 0 } else { 1 };
                    let replace = dp[i-1][j-1] + if a.chars().nth(i - 1).unwrap() == b.chars().nth(j - 1).unwrap() { 0 } else { 1 };
                    insert.min(delete).min(replace)
                }
            };
        }  
    }  
    dp[a.len()][b.len()]  
}  

#[test]  
fn test_edit_distance() {  
    assert_eq!(edit_distance("kitten", "sitting"), 3);   // k→s, e→i, 添加g
    assert_eq!(edit_distance("rust", "ruts"), 2);      // s↔t替换
}  

// 添加main函数示例
fn main() {
    println!("kitten → sitting: {}", edit_distance("kitten", "sitting"));
    println!("intention → execution: {}", edit_distance("intention", "execution"));
}